﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace QL_KHACHSAN
{
    class clsMain
    {
        //Thông báo lỗi
        public static string STR_ERROR = "Hệ thống phát hiện lỗi\nXin hãy liên hệ Dương Kỳ Hiệu\nĐT:0907774982\n\n";
        //report
        public static int intBaoCaoThang = 0;
        //
        public enum DataType { Text, Bool, Numberic, Date };
        public static FlexControls.flexControls flexConn = new FlexControls.flexControls();
        public static bool booLogin = false;
        public static string strUserLogin = "";
        //Add Data To TreeView
        internal void AddDataToTreeView(string strSQLParentNodes, string strSQLChildNodes, System.Windows.Forms.TreeView tvwTreeView)
        {
            try
            {
                tvwTreeView.Nodes.Clear();
                int intIdMenu = 0;
                string strUTF8, strTags, strValue;
                string[] strCode;
                string strSQL = "";
                //lấy danh sách menu cha
                ADODB.Recordset rsParents = new ADODB.Recordset();
                ADODB.Recordset rsChilds = new ADODB.Recordset();
                strSQL = strSQLParentNodes;
                rsParents.Open(strSQL, flexConn.fcConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, -1);

                if (rsParents.RecordCount > 0)
                {
                    for (int i = 0; i < rsParents.RecordCount; i++)
                    {
                        //Add Parent Nodes
                        System.Text.Encoding encoding = System.Text.Encoding.UTF8;
                        // Read string from binary file with UTF8 encoding
                        strUTF8 = rsParents.Fields[1].Value;


                        //Get data for ChildNode
                        strTags = rsParents.Fields[0].Value;
                        char[] delimiters = new char[] { ' ' };
                        strCode = strTags.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                        strSQL = strSQLChildNodes + "'" + Convert.ToString(strCode[0]) + "'";
                        rsChilds.Open(strSQL, flexConn.fcConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, -1);

                        //Lấy danh sách menu con
                        if (rsChilds.RecordCount > 0)
                        {
                            System.Windows.Forms.TreeNode[] nodeChilds = new TreeNode[rsChilds.RecordCount];
                            for (int j = 0; j < rsChilds.RecordCount; j++)
                            {
                                TreeNode nodeChild = new TreeNode(rsChilds.Fields[1].Value);
                                nodeChild.ImageIndex = rsChilds.Fields[2].Value;

                                nodeChilds[j] = nodeChild;
                                strValue = rsChilds.Fields[0].Value;
                                delimiters = new char[] { ' ', 'S', 'C', '_' };
                                strCode = strValue.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                                nodeChild.Tag = Convert.ToString(strCode[0]);
                                //    tvwTreeView.Nodes.Item(i).Nodes.Add(rsParents.Fields(1).Value)
                                //  tvwTreeView.Nodes.Item(i).Nodes.Item(j).ImageIndex = rsParents.Fields(2).Value
                                // strCode = Split(rsParents.Fields(0).Value.ToString, " ", 10, CompareMethod.Text)
                                //strTags = strCode(0) + ";" + rsParents.Fields(3).Value + ";" + rsParents.Fields(4).Value + ";" + rsParents.Fields(5).Value
                                //tvwTreeView.Nodes.Item(i).Nodes.Item(j).Tag = strTags
                                intIdMenu++;
                                rsChilds.MoveNext();

                            }
                            TreeNode newNode = new TreeNode(strUTF8, nodeChilds);
                            newNode.ImageIndex = rsParents.Fields[2].Value;
                            tvwTreeView.Nodes.Add(newNode);
                        }
                        /* else
                         {
                             TreeNode newNode = new TreeNode(strUTF8);
                             newNode.ImageIndex = 1;
                             delimiters = new char[] { ' ', 'S', 'M', '_', '0' };
                             strCode = strTags.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                             newNode.Tag = Convert.ToString(30);
                             tvwTreeView.Nodes.Add(newNode);
                             intIdMenu++;
                         }*/
                        rsChilds.Close();
                        rsParents.MoveNext();
                    }
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show("Add Data to TreeView\n" + ex.ToString());
            }


        }
        public void createTableForListView()
        {
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show("Create table for listview\n" + ex.ToString());
            }
        }
    }
}
